package cn.njxzc.Java2017;

/**
 * *
 * 
 * @Program Name : JavaProgram.Java2017.Graphics.java
 * @Written by : Roy Xu
 * @Creation Date : Mar 19, 2017 8:20:24 PM
 * @version : v1.00
 * @Description : polymorphism 应用场合: 不同子类可以用不同的方式实现同一共同接口，该共同接口建立了一个基本形式
 * @ModificationHistory Who When What -------- ----------
 *                      ------------------------------------------------ Roy Xu
 *                      Mar 19, 20178:20:24 PM TODO
 ** 
 */
public abstract class Graphics {
	abstract void parameter();

	abstract void area();

	public static void main(String[] args) {
		Rectangle rec = new Rectangle(1.0, 2.0);
		Circle cir = new Circle(3.0, "Red");
		Graphics[] g = { rec, cir };//attention
		for (int i = 0; i < g.length; i++) {
			g[i].parameter();
			g[i].area();
		}

	}

}

class Rectangle extends Graphics {
	double h, w;

	Rectangle(double u, double v) {
		h = u;
		w = v;
	}

	void parameter() {
		System.out.println(h + " " + w);
	}

	void area() {
		System.out.println(h * w);
	}
}

class Circle extends Graphics {
	double r;
	String c;

	Circle(double u, String v) {
		r = u;
		c = v;
	}

	void parameter() {
		System.out.println(r + " " + c);
	}

	void area() {
		System.out.println(Math.PI * r * r);
	}
}
